//
//  ItemOfYongHu.m
//  SeeTheWorld
//
//  Created by dllo on 16/2/29.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ItemOfYongHu.h"
#import "PCH.pch"
#import "YongHu.h"
#import "ModelOfYongHu.h"
#import <UIImageView+WebCache.h>


@interface ItemOfYongHu () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)NSMutableArray *arrayOfModel;

@end

@implementation ItemOfYongHu

- (void)dealloc {
    self.tableView.delegate = nil;
    self.tableView.dataSource = nil;
    [_tableView release];
    [_arrayOfModel release];
    [super dealloc];
    
}

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        self.tableView = [[UITableView alloc] initWithFrame:self.contentView.frame style:UITableViewStylePlain];
        [self.contentView addSubview:self.tableView];
        [_tableView release];
        
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        
        self.tableView.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
        
        
        [self.tableView registerClass:[YongHu class] forCellReuseIdentifier:@"pool"];
        
    }
    
    return self;
}

#pragma mark - tableView协议方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 80;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.arrayOfModel.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    

    YongHu *cell = [tableView dequeueReusableCellWithIdentifier:@"pool"];
    
    cell.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
    [cell passModel:[self.arrayOfModel objectAtIndex:indexPath.row]];

    return cell;
}

- (void)passModel:(NSMutableArray *)array {
    
    self.arrayOfModel = array;
    [self.tableView reloadData];
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    ModelOfYongHu *model = [self.arrayOfModel objectAtIndex:indexPath.row];
    
    if ([self.delegate respondsToSelector:@selector(passID:name:)]) {
        
        [self.delegate passID:model.id name:model.name];
    }
    
}












@end
